package com.mttang.util;

import java.io.IOException;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * 获取连接
 * 
 * @author lwcui
 * 
 */
public class GetRedisConnection {

	public static JedisPool pool;
	private  static Log logger = LogFactory.getLog(GetRedisConnection.class);
	static {
		Properties pro = new Properties();
		try {
			pro.load(GetRedisConnection.class.getClassLoader()
					.getResourceAsStream("redis-config.properties"));

			String host = pro.getProperty("host");
			String port = pro.getProperty("port");
			String maxActive = pro.getProperty("maxActive");
			String maxIdle = pro.getProperty("maxIdle");
			String maxWait = pro.getProperty("maxWait");
			JedisPoolConfig config = new JedisPoolConfig();
			config.setMaxActive(Integer.parseInt(maxActive));
			config.setMaxIdle(Integer.parseInt(maxIdle));
			config.setMaxWait(Integer.parseInt(maxWait));
			config.setTestOnBorrow(true);
			pool = new JedisPool(config, host, Integer.parseInt(port));
			logger.debug("create redis pool successed ... ");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			logger.debug("create redis pool failed ... "+ e.toString());
			
		}
	}

}
